<?php


namespace app\admin\controller;


use app\service\cxyunService;
use app\service\orderService;
use think\db\Where;
use think\facade\Db;
use think\facade\View;

class Car extends Common
{

    //月租车列表
    public function packageList(){
        //根据当前账号查询区域
        $com = $this->pidTokenId();
        $whe=new Where;
        $where=array();

        $whe['id'] = array('in',$com['parking_id']);
        //根据账号查询停车场
        $parkinglist = (new orderService())->parkingList($whe);
        View::assign('parkinglist',$parkinglist);
        //查询停车场ID
        if(!empty($parkinglist)){
            foreach($parkinglist as $park){
                $parkingNo[] = $park['parkingNo'];
            }
            //将数组转换成字符串
            $parkingNo = implode(',',$parkingNo);
        }else{
            $parkingNo = null;
        }

        $data = request()->get();
        // dump($data);
        //$where['carType']=1;
        $where[]=['carType','=',1];
        if (!empty($data)){
            if(!empty($data['parkingNo'])){
                //$where['parkingNo'] = $data['parkingNo'];//停车场名称
                $where[]=['parkingNo','=',$data['parkingNo']];
            }
            if(!empty($data['plateNumber'])){
                $where[]=['plateNumber','like','%'.$data['plateNumber'].'%'];
                //$where['plateNumber'] = array('like','%'.$data['plateNumber'].'%');//车牌号码//车牌号码
            }

            if(!empty($data['empName'])){
                $where[]=['empName','=',$data['empName']];
                //$where['empName'] = $data['empName'];//车主电话
            }
            if(!empty($data['empMoblie'])){
                $where[]=['empMoblie','=',$data['empMoblie']];

            }


            View::assign('where',$where);
            //$where = array_filter($where);
        }
        //var_dump($where);
        //var_dump($parkingNo);
        $page = request()->has('page') ? request()->get('page') : 1;
        $carlist =Db::name('car')
            ->where('parkingNo','in',$parkingNo)
            ->where($where)
            ->order('id desc')->paginate(100, false, [
                'page'  =>  $page,
                'query' =>  $where
            ]);

        $number = Db::name('car')
            ->where('parkingNo','in',$parkingNo)
            ->where($where)
            ->count();

        View::assign('number',$number);
        View::assign('carlist',$carlist);
        View::assign('list',$carlist);



        return View::fetch('package_list');
    }

    //月租车列表
    public function welfareList(){
        //根据当前账号查询区域
        $com = $this->pidTokenId();
        $whe=new Where;
        $where=array();

        $whe['id'] = array('in',$com['parking_id']);
        //根据账号查询停车场
        $parkinglist = (new orderService())->parkingList($whe);
        View::assign('parkinglist',$parkinglist);
        //查询停车场ID
        if(!empty($parkinglist)){
            foreach($parkinglist as $park){
                $parkingNo[] = $park['parkingNo'];
            }
            //将数组转换成字符串
            $parkingNo = implode(',',$parkingNo);
        }else{
            $parkingNo = null;
        }

        $data = request()->get();
        // dump($data);
        $where[]=['carType','=',2];
        if (!empty($data)){
            if(!empty($data['parkingNo'])){
                //$where['parkingNo'] = $data['parkingNo'];//停车场名称
                $where[]=['parkingNo','=',$data['parkingNo']];
            }
            if(!empty($data['plateNumber'])){
                $where[]=['plateNumber','like','%'.$data['plateNumber'].'%'];
                //$where['plateNumber'] = array('like','%'.$data['plateNumber'].'%');//车牌号码//车牌号码
            }

            if(!empty($data['empName'])){
                $where[]=['empName','=',$data['empName']];
                //$where['empName'] = $data['empName'];//车主电话
            }
            if(!empty($data['empMoblie'])){
                $where[]=['empMoblie','=',$data['empMoblie']];

            }


            View::assign('where',$where);
            //$where = array_filter($where);
        }
        $page = request()->has('page') ? request()->get('page') : 1;
        $carlist =Db::name('car')
            ->where('parkingNo','in',$parkingNo)
            ->where($where)->order('id desc')->paginate(100, false, [
                'page'  =>  $page,
                'query' =>  $where
            ]);
//        $list=[];
//        foreach ($carlist as $info){
//            $roominfo=Db::table("roominfo")->where("id",$info["room_id"])->find();
//            $info["addfess"]=$roominfo["group"].$roominfo["building"]."-".$roominfo["unit"]."-".$roominfo["room"];
//            $list[]=$info;
//        }
        $number = Db::name('car')
            ->where('parkingNo','in',$parkingNo)
            ->where($where)
            ->count();
        View::assign('number',$number);
        View::assign('list',$carlist);
        View::assign('carlist',$carlist);

        foreach ($data as $k => $v) {
            View::assign($k, $v);
        }
        return View::fetch('welfare_list');
    }

}